package com.scalar.chiptrack.finance.actions;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import org.apache.struts.util.LabelValueBean;
import org.apache.poi.ss.usermodel.Workbook;


import com.scalar.ScalarException;
import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.adaptor.AdaptorUtils;
import com.scalar.chiptrack.commons.Constants;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.commons.ExcelColumnProperties;
import com.scalar.chiptrack.db.DBTransaction;
import com.scalar.chiptrack.finance.CostCodeInfo;
import com.scalar.chiptrack.finance.dao.CostCodeSetupDAO;
import com.scalar.chiptrack.finance.dao.UpdateViewCostDAO;
import com.scalar.chiptrack.finance.forms.CostCodeSetupForm;
import com.scalar.chiptrack.operations.process.dao.NewProductDAO;
import com.scalar.chiptrack.operations.reports.DataDumpReportsHelper;
import com.scalar.chiptrack.users.User;
import com.scalar.chiptrack.utils.ConfigManager;
import com.scalar.chiptrack.utils.DateUtil;
import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.chiptrack.utils.ExcelUtils;

/**
 * User: ChandraSekhar
 * Date: May 30, 2007
 * Time: 11:35:07 AM
 */
public class CostCodeSetupAction extends ChipTrackAction
{
    private final String ACTION_NAME = "/costCodeSetup.do";
    String fileLocation     = null;

    public ActionForward execute (ActionMapping mapping, ActionForm form,
                              HttpServletRequest request, HttpServletResponse response) throws Exception
    {

        HashMap<String, String> errors  = new HashMap<String, String>();
		HashMap<String, String> info    = new HashMap<String, String>();
        String actionForword    = "success";
        String action           = request.getParameter ("action");
        DBTransaction dbTransaction = null;
        Workbook workbook = null;
        String exportFileName = "";
        request.setAttribute( SessionKeys.INFO_MESSAGES, info );
        request.setAttribute ( SessionKeys.ERROR_MESSAGES, errors );

        HttpSession session = request.getSession ();
        User user = ( User ) session.getAttribute ( SessionKeys.USER_KEY );
        if ( user == null )
        {
            session.setAttribute ( SessionKeys.SOURCE_PAGE_KEY, ACTION_NAME + "?" + request.getQueryString () );
            return ( mapping.findForward ( "login" ) );
        }
        
        if ( action == null )
        {
            action = "";
        }

        CostCodeSetupForm costCodeSetupForm = (CostCodeSetupForm) form;

        String currentYear = StringUtils.formatDateToString(new Date(), "yyyy");
        String currentQuater = DateUtil.getCurrentQuarter();

		if ( action.equals("") )
		{
            request.setAttribute( "quarterList", DateUtil.loadQuarterList() );
            request.setAttribute ( "yearList", DateUtil.getYearList() );
            costCodeSetupForm.setQuater (  Integer.parseInt ( currentQuater )  );
			costCodeSetupForm.setYear ( Integer.parseInt ( currentYear ) );
		}
		else if ( action.equalsIgnoreCase ( "search" ) )
		{
            ArrayList<CostCodeInfo> costCodeList = CostCodeSetupDAO.loadCostCodes( costCodeSetupForm.getYear(), costCodeSetupForm.getQuater() );
            if ( costCodeList == null || costCodeList.size() <= 0 )
            {
                //By Default To Display three Empty rows , to enter the Cost Code details
                costCodeList = new ArrayList<CostCodeInfo>();
                costCodeList.add( new CostCodeInfo() );
                costCodeList.add( new CostCodeInfo() );
                costCodeList.add( new CostCodeInfo() );
            }
            
            costCodeSetupForm.setCostCodeList( costCodeList );

            actionForword = "costCodeView";
            return ( mapping.findForward ( actionForword ) );
		}
        else if ( action.equalsIgnoreCase("saveCostCodes") )
        {
            boolean success = false;
            
            dbTransaction = DBTransaction.getInstance ();
            dbTransaction.begin ();
            try
            {
                CostCodeSetupDAO.saveCostCodeDetails( dbTransaction, costCodeSetupForm.getCostCodeList(), costCodeSetupForm.getYear(), costCodeSetupForm.getQuater() );
                success = true;
            }
            catch(Exception e)
            {
                success = false;
                e.printStackTrace();
            }
            finally
            {
                try
                {
                    if( dbTransaction != null )
                    {
                        if( success )
                        {
                            dbTransaction.commit();
                            info.put ("Cost Codes have been saved/updated successfully", null);
                        }
                        else
                        {
                            dbTransaction.rollback();
                            errors.put ("Unable to save Cost Codes into Data Base", null);
                        }
                    }
                }
                catch(Exception e1)
                {
                    e1.printStackTrace();
                }
            }

            request.setAttribute( "quarterList", DateUtil.loadQuarterList() );
            request.setAttribute ( "yearList", DateUtil.getYearList() );
        }
        else if ( action.equalsIgnoreCase( "uploadFile"	) )
        {
        	actionForword = "uploadFile";
        	request.setAttribute( "hoursList", DateUtil.loadHours() );
        	request.setAttribute( "minutesList", DateUtil.loadMinutes() );
        	request.setAttribute( "ampmList", DateUtil.loadAmPm() );

            costCodeSetupForm.setScheduleMinute( (DateUtil.getCurrentMinute() + 5) +"" );
            costCodeSetupForm.setScheduleTime( DateUtil.getCurrent12Hour() +"" );
            costCodeSetupForm.setAm_pm( DateUtil.getCurrentAmPm()+"");
        }
        else if ( action.equalsIgnoreCase("upload") )
        {
        	actionForword = "uploadFile";
            FormFile file = costCodeSetupForm.getTheFile();
            String fileName= file.getFileName();
            String jobName = null;

            try
            {
                fileLocation = ConfigManager.getCostCodePortingDirectory();

                AdaptorUtils.makeAllAdaptorDirs( fileLocation );
                
                try
                {
                    //To remove already Existed Files, IF Any
                    AdaptorUtils.removeOldFiles( fileLocation, null );
                }
                catch(Exception e )
                {
                   errors.put("File is in use",null);
                }

                if( ( fileName != null ) && ( fileName.trim().length() != 0 ) )
                {
                    if( fileName.endsWith(".xls") || fileName.endsWith(".XLS") )
                    {
                        if ("unitCostFile".equalsIgnoreCase( costCodeSetupForm.getFileType() ) )
                        {
                            fileName = "Unit_Cost_Deatil_" + AdaptorUtils.getTimeAsString();
                            jobName  = "UNIT COST PARSER";
                        }
                        else
                        {
                            fileName = "Cost_Codes_" + AdaptorUtils.getTimeAsString();
                            jobName  = "COST CODE PARSER";
                        }

                        InputStream stream = file.getInputStream();
                        OutputStream bos = new FileOutputStream( fileLocation+"/"+fileName );
                        int bytesRead = 0;
                        byte[] buffer = new byte[8192];

                        while ((bytesRead = stream.read(buffer, 0, 8192)) != -1)
                        {
                            bos.write(buffer, 0, bytesRead);
                        }

                        bos.close();
                        info.put("File uploaded successfully",null);
                    }
                    else
                    {
                        errors.put("Only Files in EXCEL format can be uploaded",null);
                    }
                }
                CostCodeSetupDAO.saveSchedule( costCodeSetupForm , jobName );
                info.put( "Job Scheduled successfully", null );
            }
            catch(FileNotFoundException fnfe)
            {
                fnfe.printStackTrace();
                throw new ScalarException(" Specified file : "+fileName, fnfe);
            }
            catch(IOException ioe)
            {
                ioe.printStackTrace();
                throw new ScalarException(" Streaming is failed : "+fileName, ioe);
            }
        	request.setAttribute( "hoursList", DateUtil.loadHours() );
        	request.setAttribute( "minutesList", DateUtil.loadMinutes() );
        	request.setAttribute( "ampmList", DateUtil.loadAmPm() );
            request.setAttribute( "quarterList", DateUtil.loadQuarterList() );
            request.setAttribute( "yearList", DateUtil.getYearList() );
        }
        else if ("waferPkgCost".equalsIgnoreCase( action ) )
        {
            actionForword = "waferPkgCost";
            ArrayList<LabelValueBean> partNumberList    = new ArrayList<LabelValueBean>();
            partNumberList.addAll( NewProductDAO.loadPartNumbers(null, 0, Constants.LOCATION_TYPE_DIE_BANK, true , true, true, 0) );
            partNumberList.addAll( NewProductDAO.loadPartNumbers(null, 0, Constants.LOCATION_TYPE_ASSEMBLY, true , true, true, 0) );
            partNumberList.addAll( NewProductDAO.getPartNumbersByProcessParameter( null, Constants.LOCATION_TYPE_FINISHED_GOODS, "SPECIFIC_COST" , "TRUE" ) );
            request.setAttribute( "partNumberList", partNumberList );
            request.setAttribute( "packagesList", UpdateViewCostDAO.loadPackages(null) );
            request.setAttribute( "quarterList", DateUtil.loadQuarterList() );
            request.setAttribute( "yearList", DateUtil.getYearList() );
            costCodeSetupForm.setQuater (  Integer.parseInt ( currentQuater )  );
			costCodeSetupForm.setYear ( Integer.parseInt ( currentYear ) );

            //costCodeSetupForm.setCostCodeList( CostCodeSetupDAO.loadWaferPartandPkgs(costCodeSetupForm.getProcessStepId(), costCodeSetupForm.getPackageType()));
        }
        else if( "searchwaferPkgCost".equalsIgnoreCase( action ) )
        {
            actionForword = "waferPkgCost";

            ArrayList<LabelValueBean> partNumberList    = new ArrayList<LabelValueBean>();
            partNumberList.addAll( NewProductDAO.loadPartNumbers(null, 0, Constants.LOCATION_TYPE_DIE_BANK, true , true, true, 0) );
            partNumberList.addAll( NewProductDAO.loadPartNumbers(null, 0, Constants.LOCATION_TYPE_ASSEMBLY, true , true, true, 0) );
            partNumberList.addAll( NewProductDAO.getPartNumbersByProcessParameter( null, Constants.LOCATION_TYPE_FINISHED_GOODS, "SPECIFIC_COST" , "TRUE" ) );
            request.setAttribute( "partNumberList", partNumberList );
            request.setAttribute( "packagesList", UpdateViewCostDAO.loadPackages(null) );
            request.setAttribute( "quarterList", DateUtil.loadQuarterList() );
            request.setAttribute( "yearList", DateUtil.getYearList() );
            
            costCodeSetupForm.setProcessType( NewProductDAO.getProcessTypeByProcessStep_ID( costCodeSetupForm.getProcessStepId() ) );
            if( "TRUE".equalsIgnoreCase( NewProductDAO.getProcessParameterValue( null, costCodeSetupForm.getProcessStepId(), "IS_MEMS_WAFER") ))
            {
            	costCodeSetupForm.setProcessType( "MEMS" );
            }
            ArrayList<CostCodeInfo> costCodeList = CostCodeSetupDAO.loadWaferPartandPkgs(costCodeSetupForm.getProcessStepId(), costCodeSetupForm.getPackageType(), costCodeSetupForm.getQuater(), costCodeSetupForm.getYear());
            costCodeSetupForm.setCostCodeList( costCodeList );
        }
        else if( "impPrevQtrValues".equalsIgnoreCase( action ) )
        {
            actionForword = "waferPkgCost";

            ArrayList<LabelValueBean> partNumberList    = new ArrayList<LabelValueBean>();
            partNumberList.addAll( NewProductDAO.loadPartNumbers(null, 0, Constants.LOCATION_TYPE_DIE_BANK, true , true, true, 0) );
            partNumberList.addAll( NewProductDAO.loadPartNumbers(null, 0, Constants.LOCATION_TYPE_ASSEMBLY, true , true, true, 0) );
            partNumberList.addAll( NewProductDAO.getPartNumbersByProcessParameter( null, Constants.LOCATION_TYPE_FINISHED_GOODS, "SPECIFIC_COST" , "TRUE" ) );
            request.setAttribute( "partNumberList", partNumberList );
            request.setAttribute( "packagesList", UpdateViewCostDAO.loadPackages(null) );
            request.setAttribute( "quarterList", DateUtil.loadQuarterList() );
            request.setAttribute( "yearList", DateUtil.getYearList() );
            
            costCodeSetupForm.setProcessType( NewProductDAO.getProcessTypeByProcessStep_ID( costCodeSetupForm.getProcessStepId() ) );
            if( "TRUE".equalsIgnoreCase( NewProductDAO.getProcessParameterValue( null, costCodeSetupForm.getProcessStepId(), "IS_MEMS_WAFER") ))
            {
            	costCodeSetupForm.setProcessType( "MEMS" );
            }
            
            int prvQtr = 1;
            int prvYear = Integer.parseInt ( currentYear );
            
            if ( costCodeSetupForm.getQuater() == 1 )
            {
            	prvQtr = 4;
            	prvYear = costCodeSetupForm.getYear() - 1;
            }
            else
            {
            	prvQtr = costCodeSetupForm.getQuater() - 1;
            	prvYear = costCodeSetupForm.getYear();
            }
            costCodeSetupForm.setCostCodeList( CostCodeSetupDAO.loadWaferPartandPkgs(costCodeSetupForm.getProcessStepId(), costCodeSetupForm.getPackageType(), prvQtr, prvYear ));
        }
        else if ("savewaferPkgCost".equalsIgnoreCase(action) )
        {
            boolean success = false;
            actionForword = "waferPkgCost";
            dbTransaction = DBTransaction.getInstance ();
            dbTransaction.begin ();
            try
            {
                CostCodeSetupDAO.saveWaferPartPkgCostDetails( dbTransaction, costCodeSetupForm.getCostCodeList(), user.getUserId(), costCodeSetupForm.getQuater(), costCodeSetupForm.getYear() );
                success = true;
            }
            catch(Exception e)
            {
                success = false;
                e.printStackTrace();
            }
            finally
            {
                try
                {
                    if( dbTransaction != null )
                    {
                        if( success )
                        {
                            dbTransaction.commit();
                            info.put ("Wafer part Pkg Cost have been saved/updated successfully", null);
                        }
                        else
                        {
                            dbTransaction.rollback();
                            errors.put ("Unable to save Wafer part Pkg Cost into Data Base", null);
                        }
                    }
                }
                catch(Exception e1)
                {
                    e1.printStackTrace();
                }
            }

            ArrayList<LabelValueBean> partNumberList    = new ArrayList<LabelValueBean>();
            partNumberList.addAll( NewProductDAO.loadPartNumbers(null, 0, Constants.LOCATION_TYPE_DIE_BANK, true , true, true, 0) );
            partNumberList.addAll( NewProductDAO.loadPartNumbers(null, 0, Constants.LOCATION_TYPE_ASSEMBLY, true , true, true, 0) );
            partNumberList.addAll( NewProductDAO.getPartNumbersByProcessParameter( null, Constants.LOCATION_TYPE_FINISHED_GOODS, "SPECIFIC_COST" , "TRUE" ) );
            costCodeSetupForm.setProcessType( NewProductDAO.getProcessTypeByProcessStep_ID( costCodeSetupForm.getProcessStepId() ) );
            if( "TRUE".equalsIgnoreCase( NewProductDAO.getProcessParameterValue( null, costCodeSetupForm.getProcessStepId(), "IS_MEMS_WAFER") ))
            {
            	costCodeSetupForm.setProcessType( "MEMS" );
            }
            costCodeSetupForm.setCostCodeList( CostCodeSetupDAO.loadWaferPartandPkgs(costCodeSetupForm.getProcessStepId(), costCodeSetupForm.getPackageType(), costCodeSetupForm.getQuater(), costCodeSetupForm.getYear()));
            request.setAttribute( "partNumberList", partNumberList );
            request.setAttribute("packagesList", UpdateViewCostDAO.loadPackages(null) );
            request.setAttribute( "quarterList", DateUtil.loadQuarterList() );
            request.setAttribute( "yearList", DateUtil.getYearList() );
        }
        else if ("fgStdCostReport".equalsIgnoreCase( action ) )
        {               
            ArrayList reportList = CostCodeSetupDAO.getFgStdCostReport( null, costCodeSetupForm );

            ExcelColumnProperties colProps1 = new ExcelColumnProperties("CMOS Die Cost");
            colProps1.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps2 = new ExcelColumnProperties("MEMS Die Cost");
            colProps2.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps3 = new ExcelColumnProperties("ASSEMBLY Step COST");
            colProps3.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps4 = new ExcelColumnProperties("Assembly Out Cost");
            colProps4.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps5 = new ExcelColumnProperties("Test Step Cost Per Sec");
            colProps5.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps6 = new ExcelColumnProperties("Test Out Cost");
            colProps6.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps7 = new ExcelColumnProperties("TR Step Cost");
            colProps7.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps8 = new ExcelColumnProperties("FG Cost");
            colProps8.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);

            ExcelColumnProperties colProps9 = new ExcelColumnProperties("Assembly Yield");
            colProps9.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            ExcelColumnProperties colProps10 = new ExcelColumnProperties("Test Yield");
            colProps10.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            ExcelColumnProperties colProps11 = new ExcelColumnProperties("TR Yield");
            colProps11.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            List<ExcelColumnProperties> list = new ArrayList<ExcelColumnProperties>();

            list.add(colProps1);  list.add(colProps2); list.add(colProps3);

            list.add(colProps4); list.add(colProps5); list.add(colProps6); list.add(colProps7);
            list.add(colProps8); list.add(colProps9); list.add(colProps10); list.add(colProps11);

            workbook =  DataDumpReportsHelper.getWorkbook( reportList, "FG Standrad Cost Report", null, null,  list );
            
            exportFileName = "FG Standard Cost Report-" + DateUtil.getTimeStamp() ;

            //To GENERATE THE EXCEL REPORT
            ExcelUtils.generateExcelReport( workbook, exportFileName, response );
        }
        else if ("memsStdCostReport".equalsIgnoreCase( action ) )
        {
            ArrayList reportList = CostCodeSetupDAO.getMemsStdCostReport( null, costCodeSetupForm );

            ExcelColumnProperties colProps4 = new ExcelColumnProperties("Raw Wafer Cost");
            colProps4.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps5 = new ExcelColumnProperties("ZRO EXP2 Cost");
            colProps5.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps6 = new ExcelColumnProperties("Zero EXP2 CUMM COST");
            colProps6.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps7 = new ExcelColumnProperties("Epi VT Cost");
            colProps7.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps8 = new ExcelColumnProperties("Epi VT CUMM Cost");
            colProps8.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps9 = new ExcelColumnProperties("VN_EXP Cost");
            colProps9.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps10 = new ExcelColumnProperties("VN_EXP CUMM COST");
            colProps10.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps11 = new ExcelColumnProperties("Epi Seal Cost");
            colProps11.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps12 = new ExcelColumnProperties("Epi Seal CUMM Cost");
            colProps12.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps13 = new ExcelColumnProperties("Fab Cost");
            colProps13.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps14 = new ExcelColumnProperties("Fab CUMM COST");
            colProps14.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps15 = new ExcelColumnProperties("Pre_Grind Cost");
            colProps15.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps16 = new ExcelColumnProperties("Pre_Grind CUMM Cost");
            colProps16.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps17 = new ExcelColumnProperties("Back Grind Step Cost");
            colProps17.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps18 = new ExcelColumnProperties("Back Grind CUMM Cost");
            colProps18.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps19 = new ExcelColumnProperties("Sort Step Cost");
            colProps19.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps20 = new ExcelColumnProperties("Sort CUMM Cost");
            colProps20.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps21 = new ExcelColumnProperties("Total Wafer Cost");
            colProps21.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps22 = new ExcelColumnProperties("Die Bank Die Cost");
            colProps22.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);


            ExcelColumnProperties colProps1 = new ExcelColumnProperties("Mix Match Yield");
            colProps1.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            ExcelColumnProperties colProps2 = new ExcelColumnProperties("Sort Yield");
            colProps2.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            ExcelColumnProperties colProps3 = new ExcelColumnProperties("Back Grind Yield");
            colProps3.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);

            List<ExcelColumnProperties> list = new ArrayList<ExcelColumnProperties>();

            list.add(colProps1);  list.add(colProps2); list.add(colProps3);

            list.add(colProps4); list.add(colProps5); list.add(colProps6); list.add(colProps7);
            list.add(colProps8); list.add(colProps9); list.add(colProps10);
            list.add(colProps11); list.add(colProps12); list.add(colProps13); list.add(colProps14);
            list.add(colProps15); list.add(colProps16); list.add(colProps17); list.add(colProps18);
            list.add(colProps19); list.add(colProps20); list.add(colProps21); list.add(colProps22);

            workbook =  DataDumpReportsHelper.getWorkbook(reportList, "MEMS Standrad Cost Report", null, null, list );

            exportFileName = "MEMS Standard Cost Report-" + DateUtil.getTimeStamp() ;

            //To GENERATE THE EXCEL REPORT
            ExcelUtils.generateExcelReport( workbook, exportFileName, response );
        }
        else if ("cmosStdCostReport".equalsIgnoreCase( action ) )
        {
            ArrayList reportList = CostCodeSetupDAO.getCmosStdCostReport( null, costCodeSetupForm );
            
            ExcelColumnProperties colProps1 = new ExcelColumnProperties("Fab Cost");
            colProps1.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps2 = new ExcelColumnProperties("Back Grind Step Cost");
            colProps2.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps3 = new ExcelColumnProperties("Back Grind CUMM Cost");
            colProps3.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps4 = new ExcelColumnProperties("Total Wafer Cost");
            colProps4.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps5 = new ExcelColumnProperties("Die Bank Cost");
            colProps5.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);

            List<ExcelColumnProperties> list = new ArrayList<ExcelColumnProperties>();

            list.add(colProps1);  list.add(colProps2); list.add(colProps3);
            list.add(colProps4);  list.add(colProps5);

            workbook =  DataDumpReportsHelper.getWorkbook( reportList, "CMOS Standrad Cost Report", null, null, list );

            exportFileName = "CMOS Standard Cost Report-" + DateUtil.getTimeStamp() ;

            //To GENERATE THE EXCEL REPORT
            ExcelUtils.generateExcelReport( workbook, exportFileName, response );
        }
        else if ("assyStdCostReport".equalsIgnoreCase( action ) )
        {
            ArrayList reportList = CostCodeSetupDAO.getAssyStdCostReport( null, costCodeSetupForm );

            ExcelColumnProperties colProps1 = new ExcelColumnProperties("CMOS Die Cost");
            colProps1.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps2 = new ExcelColumnProperties("MEMS Die Cost");
            colProps2.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps3 = new ExcelColumnProperties("ASSEMBLY Step COST");
            colProps3.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps4 = new ExcelColumnProperties("Assembly Out Cost");
            colProps4.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);

            ExcelColumnProperties colProps5 = new ExcelColumnProperties("Assembly Yield");
            colProps5.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            
            List<ExcelColumnProperties> list = new ArrayList<ExcelColumnProperties>();

            list.add(colProps1);  list.add(colProps2); list.add(colProps3);
            list.add(colProps4); list.add(colProps5);

            workbook =  DataDumpReportsHelper.getWorkbook( reportList, "Assm Standrad Cost Report", null, null,  list );

            exportFileName = "Assm Standard Cost Report-" + DateUtil.getTimeStamp() ;

            //To GENERATE THE EXCEL REPORT
            ExcelUtils.generateExcelReport( workbook, exportFileName, response );
        }
        else if ("cummStdCostReport".equalsIgnoreCase( action ) )
        {
            ArrayList reportList = CostCodeSetupDAO.getCummStdCostReport( null );
            
            ExcelColumnProperties colProps1 = new ExcelColumnProperties("FAB COST");
            colProps1.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps2 = new ExcelColumnProperties("BUMP COST");
            colProps2.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps3 = new ExcelColumnProperties("BUMP OUT COST");
            colProps3.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps4 = new ExcelColumnProperties("SORT COST");
            colProps4.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps5 = new ExcelColumnProperties("SORT OUT COST");
            colProps5.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps6 = new ExcelColumnProperties("ASSEMBLY COST");
            colProps6.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps7 = new ExcelColumnProperties("BOM COST");
            colProps7.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps8 = new ExcelColumnProperties("ASSEMBLY OUT COST");
            colProps8.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps9 = new ExcelColumnProperties("FT COST");
            colProps9.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps10 = new ExcelColumnProperties("FT OUT COST");
            colProps10.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            ExcelColumnProperties colProps11 = new ExcelColumnProperties("FG COST");
            colProps11.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
            
            ExcelColumnProperties colProps12 = new ExcelColumnProperties("FAB YIELD");
            colProps12.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            ExcelColumnProperties colProps13 = new ExcelColumnProperties("SORT YIELD");
            colProps13.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            ExcelColumnProperties colProps14 = new ExcelColumnProperties("BUMP YIELD");
            colProps14.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            ExcelColumnProperties colProps15 = new ExcelColumnProperties("ASSEMBLY YIELD");
            colProps15.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);
            ExcelColumnProperties colProps16 = new ExcelColumnProperties("FT YIELD");
            colProps16.setCellStyle(ExcelColumnProperties.CELL_STYLE_FLOAT_PER);


            List<ExcelColumnProperties> list = new ArrayList<ExcelColumnProperties>();

            list.add(colProps1);  list.add(colProps2); list.add(colProps3);
            list.add(colProps4);  list.add(colProps5);
            list.add(colProps6);  list.add(colProps7); list.add(colProps8);
            list.add(colProps9);  list.add(colProps10);list.add(colProps11);
            list.add(colProps16);  list.add(colProps12); list.add(colProps13);
            list.add(colProps14);  list.add(colProps15);

            workbook =  DataDumpReportsHelper.getWorkbook( reportList, "CMOS Standrad Cost Report", null, null, list );

            exportFileName = "Cummulative Standard Cost Report-" + DateUtil.getTimeStamp() ;

            //To GENERATE THE EXCEL REPORT
            ExcelUtils.generateExcelReport( workbook, exportFileName, response );
        }
        else if ("updateViewCostTables".equalsIgnoreCase(action))
        {
             CostCodeSetupDAO.saveUpdateCostDetails(null, costCodeSetupForm);
             info.put("Successfully updated cost details", null);
        }
        return (mapping.findForward ( actionForword ) );
    }
  
}
